<?php
/**
 * 用户逻辑层
 *
 */

namespace App\Biz;

use App\Utils\Log;

class AdminMenu extends Base
{
    /**
     * 获取所有菜单
     * @param string $menu_lists
     */
    public static function getMenu(string $menu_lists)
    {
        $detail = \App\Dao\AdminMenu::getAllMenu($menu_lists);
        return $detail->toArray();
    }


    /**
     * 所有菜单进行分类
     * @param array $menuList
     * @return array
     */
    public static function generateMenuTree(array $items)
    {
        $tree     = [];
        $packData = [];
        foreach ($items as $data) {
            $packData[$data['id']] = $data;
        }
        foreach ($packData as $key => $val) {
            if ($val['parent_id'] == 0) {//代表跟节点
                $tree[] =& $packData[$key];
            } else {
                //找到其父类
                $packData[$val['parent_id']]['child'][] =& $packData[$key];
            }
        }
        return $tree;
    }
}